using System;
using UnityEngine;
using UnityEngine.EventSystems;

namespace HurricanePackage
{
    public static class UGUIUtil
    {
        //普通点击
        public static void RegisterUIClick(GameObject _go, Action<PointerEventData> _action)
        {
            if(_go == null)
                return;
            UGUIClickListener listener = UGUIClickListener.Get(_go);
            if(listener != null)
                listener.RegisterUIClick(_action);
        }
        
        public static void UnRegisterUIClick(GameObject _go, Action<PointerEventData> _action,bool _remove = false)
        {
            if(_go == null)
                return;
            UGUIClickListener listener = UGUIClickListener.Get(_go);
            if (listener != null)
            {
                listener.UnRegisterUIClick(_action);
                if (_remove)
                    listener.RemoveListener();
            }
        }
        //长按
        public static void RegisterUILongPress(GameObject _go, Action<PointerEventData> _action)
        {
            if(_go == null)
                return;
            UGUIClickListener listener = UGUIClickListener.Get(_go);
            if(listener != null)
                listener.RegisterUILongPress(_action);
        }
        
        public static void UnRegisterUILongPress(GameObject _go, Action<PointerEventData> _action,bool _remove = false)
        {
            if(_go == null)
                return;
            UGUIClickListener listener = UGUIClickListener.Get(_go);
            if (listener != null)
            {
                listener.UnRegisterUILongPress(_action);
                if (_remove)
                    listener.RemoveListener();
            }
        }

        #region 拖拽

        public static void RegisterUIBeginDrag(GameObject _go, Action<PointerEventData> _action)
        {
            UGUIDragListener listener =  UGUIDragListener.Get(_go);
            if (listener != null)
            {
                listener.RegisterBeginDrag(_action);
            }
        }

        public static void UnRegisterUIBeginDrag(GameObject _go, Action<PointerEventData> _action, bool _remove = false)
        {
            UGUIDragListener listener =  UGUIDragListener.Get(_go);
            if (listener != null)
            {
                listener.UnRegisterBeginDrag(_action);
                if (_remove)
                    listener.RemoveListener();
            }
        }
        
        
        public static void RegisterUIDrag(GameObject _go, Action<PointerEventData> _action)
        {
            UGUIDragListener listener =  UGUIDragListener.Get(_go);
            if (listener != null)
            {
                listener.RegisterDrag(_action);
            }
        }

        public static void UnRegisterUIDrag(GameObject _go, Action<PointerEventData> _action, bool _remove = false)
        {
            UGUIDragListener listener =  UGUIDragListener.Get(_go);
            if (listener != null)
            {
                listener.UnRegisterDrag(_action);
                if(_remove)
                    listener.RemoveListener();
            }
        }
        public static void RegisterUIEndDrag(GameObject _go, Action<PointerEventData> _action)
        {
            UGUIDragListener listener =  UGUIDragListener.Get(_go);
            if (listener != null)
            {
                listener.RegisterEndDrag(_action);
            }
        }

        public static void UnRegisterUIEndDrag(GameObject _go, Action<PointerEventData> _action, bool _remove = false)
        {
            UGUIDragListener listener =  UGUIDragListener.Get(_go);
            if (listener != null)
            {
                listener.UnRegisterEndDrag(_action);
                if(_remove)
                    listener.RemoveListener();
            }
        }

        public static void RegisterUIMove(GameObject _go, Action<AxisEventData> _action)
        {
            UGUIDragListener listener =  UGUIDragListener.Get(_go);
            if (listener != null)
            {
                listener.RegisterMove(_action);
            }
        }

        public static void UnRegisterUIMove(GameObject _go, Action<AxisEventData> _action, bool _remove = false)
        {
            UGUIDragListener listener =  UGUIDragListener.Get(_go);
            if (listener != null)
            {
                listener.UnRegisterMove(_action);
                if(_remove)
                    listener.RemoveListener();
            }
        }
        
        #endregion
        
        
        
        
    }
}